package com.exercise.AndroidCamera;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Typeface;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.webkit.WebView.FindListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.HorizontalScrollView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;
/*
기능 : 그룹리스트 어탭터
작성 : 하드캔
완료일 : 2014.09.26 
	*/
public class GroupListAdapter extends BaseAdapter{
	Intent i;
	String groupID;
	String userID;
	Typeface tf;
	
	private Context context;
	private int groupCount, layoutId;
	private ArrayList<String> groupIdList, groupNameList;
	private LayoutInflater inflater;
	
	public GroupListAdapter(Context context, int layoutId, ArrayList<String> groupIdList, ArrayList<String> groupNameList, int groupCount, String userID) {
		// TODO Auto-generated constructor stub
		this.context = context;
		this.layoutId = layoutId;
		this.groupIdList = groupIdList;
		this.groupNameList = groupNameList;
		this.groupCount = groupCount;
		this.userID = userID;
		tf = Typeface.createFromAsset(context.getAssets(), "fonts/whitechok.ttf");
		inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return groupIdList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return groupIdList.get(position);
	}
	
	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}
	
	private class ViewHolder 
	{
		TextView apkName;
		CheckBox ck1;
	}
	
	public static class ViewHolder1{
		Button group_button;
	}
	
	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		final int pos = position;
		ViewHolder1 holder = null;

		
		// TODO Auto-generated method stub
		if(convertView == null) 
		{
			holder = new ViewHolder1();
			convertView = inflater.inflate(layoutId, parent, false);
			holder.group_button = (Button)convertView.findViewById(R.id.groupButton);
			holder.group_button.setText(groupNameList.get(position));
			holder.group_button.setTypeface(tf);
			holder.group_button.setTextSize(10);
			holder.group_button.setGravity(Gravity.CENTER);
			convertView.setTag(holder);
		}
		
		else
		{
			holder.group_button.setTypeface(tf);
			holder.group_button.setTextSize(10);
			holder.group_button.setGravity(Gravity.CENTER);
			holder = (ViewHolder1)convertView.getTag();
		}
		holder.group_button.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
		    	i = new Intent(context, GroupInfoActivity.class);
		    	Activity a = (Activity)context;
		    	groupID = groupIdList.get(position);
		    	i.putExtra("groupID", groupID);
		    	i.putExtra("userID", userID);
		    	a.startActivityForResult(i,3);
			}
		});
		
		notifyDataSetChanged();
		return convertView;
	}
}
